
#main

// dots style
var str_dict_list String.Dict.Array = [['a': 'abc', 'b': '123.1']]
var int_dict Int.Dict = [:]

// [] [:] style
var str_list String[] = []
var float_dict_array Float[:][] = []


str_list[] = 'str'  // okay
// str_list[] = Exception('message')  // error

// int_dict['k1'] = '123' // error
int_dict['k2'] = -123   // okay

float_dict_array[] = ['abc': 123.12]   // okay
// float_dict_array[] = ['abc': 'ddd']   // error

// auto style
arr = [] // Any.Array
arr.push([1, 2, 3])
arr.push("hello")

echo arr.pop()

arr1 = [1, 2, 3]
arr2 = [4, 5, 6]
arr3 = arr1 concat arr2

var dict = [:]
dict[1.1] = 1

var key = 1
var key1 Any = 1
var key2 = 1.1
var key3 = false

dict1 = [
	key: "abc", // some comments
	key1: "abc", // some comments
	key3: "abc", // some comments
	"k1": "v1", /* some comments */
]

dict2 = [
	key2: "abc", /* some comments
	 */
	"k1": "v1", // some comments
]

for key, val in dict1 {
	echo <span>$key: $val</span>
}

var users = [
	["id": 1, "name": "name1"],
	["id": 2, "name": "name2"],
	["id": 3, "name": "name3"],
]

var id2name = [:]
for user in users {
	id2name[user['id'] as String] = user['name']
}

// array map
var mapped = users.map((item) => {
	return '${item['id']} - ${item['name']}'
})
var_dump(mapped)

// array reduce
var reduced = [1, 2, 3].reduce((carry, item) => {
	return carry as Int + item as Int
}, 10)
var_dump(reduced)

// array filter
var filtered = [0, 1, 2, 3, 4, 5].filter((item) => {
	if item as Int % 2 == 0 {
		return true
	}
})
var_dump(filtered)
